import requests
import json

# data = {
#     'username':'wangyu',
#     'password':'123456'
# }
# url_post = 'http://127.0.0.1:8000/login/'
# url_get = 'http://127.0.0.1:8000/list'
# url = 'http://127.0.0.1:8000/login/?username=test&password=123'

# url = 'http://coding.imooc.com/api/cate'
# data = {
# "timestamp":1550797305579,
#
#
# }
# data = {"status":1,"data":[],"errorCode":1006,"errorDesc":"token error","timestamp":1550797305579}

class RunMain:

    def send_get(self,url,data):

        res = requests.get(url=url,params=data).json()
        return json.dumps(res,indent=2,sort_keys=True)


    def send_post(sefl,url,data):
        res = requests.post(url=url,data=data).json()
        return json.dumps(res,indent=2,sort_keys=True)

    def run_main(self,url,method,data=None):
        res = None
        if method == 'GET':
            res = self.send_get(url,data)
        else:
            res = self.send_post(url,data)
        return res
if __name__ == '__main__':

    data = {
        'username': 'wangyu',
        'password': '123456'
    }
    url_post = 'http://127.0.0.1:8000/login/'
    url_get = 'http://127.0.0.1:8000/list'

    # run_get = RunMain(url_get,'GET',data)
    # run_post = RunMain(url_post,'POST',data)
    # print(run_get.res)
    # print(run_post.res)
    # print(send_post(url_post,data))
    # print(send_get(url_get,data))
    run = RunMain()
    # print(run.run_main(url_get,'GET',data))
    print(run.run_main(url_post,'POST',data))


